<?php
require_once ('newsletter.class.php');

add_action("admin_menu", "myconfig_admins_newsletter");
function myconfig_admins_newsletter()
{
	add_menu_page( __('Newsletter',THEMENAME), __('Đăng ký nhận tin',THEMENAME), 'administrator', 'newsletter', 'my_theme_setting_newsletter');
	add_submenu_page( 'newsletter', __("Danh sách",WS24_THEMENAME), __("Danh sách",WS24_THEMENAME), 'administrator', 'list-newsletter', 'ws24_theme_func_subnewletter');
	add_menu_page( 'Liên hệ', 'Liên hệ', 'administrator', 'my-dang-ky-contact-us', 'my_theme_dang_ky_contact_us');
}

function my_theme_dang_ky_contact_us()
{
	include TEMPLATEPATH.'/ws24options/view-contact-us.php';
}

function my_theme_setting_newsletter()
{
	$sourcePath = get_bloginfo('template_url').'/ws24options/';	
	?>
	<link href="<?php echo $sourcePath;?>newsletter/newsletter.css" type="text/css" rel="stylesheet">	
	<script type="text/javascript" src="<?php echo $sourcePath;?>newsletter/newsletter.js"></script>	
	<div style="width: 98%;" id="my_theme_options_content">
                
         <div style="float: left; width: 100%;">
	         <h1 class="contactlist"><?php echo __("Đăng ký nhận tin qua email",THEMENAME);?></h1>
		  </div> 		       
           <div class="box-tabs">        
           <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
           <?php   // Process form 
           if($_SERVER['REQUEST_METHOD'] == 'POST')
           {
           		if(wp_verify_nonce($_POST['act_newsletter_send_data'],'act-newsletter-send-data'))
           		{
           			update_option("ws24-newsletter-data", $_POST['ws24newsletterdata']);           			
           		}
           }
           
           $newsletterdata = get_option("ws24-newsletter-data");           
           ?>
           
           <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
           
           		<div class="newsletter-l">
           			<form action="" method="post">
	           			<div class="bl2">
	           				<p>
	           					<label><b><?php echo __("Cài đặt nội dung email mẫu",WS24_THEMENAME);?></b></label>
	           				</p>
	           				
	           				<p>
	           					<input type="text" name="ws24newsletterdata[subject]" placeholder="<?php echo __('Subject',WS24_THEMENAME);?>" id="subject" value="<?php echo  ($newsletterdata['subject']);?>">
	           				</p>
	           				<!-- 
	           				<p>	
	           					<textarea rows="" cols="" name="content" id="content"><?php echo (get_option("ws24-newsletter-data-content"));?></textarea>
	           				</p>
	           				-->
	           				<div style="float: left; width: 100%;">
	           				<?php 
	           				$content = $newsletterdata['content'];
	           				$editor_id = 'ws24newsletterdata[content]';
	           				
	           				wp_editor( $content, $editor_id );
	           				?>	
	           				</div>
	           			</div>
	           			<div class="bl3">
	           				<p>
	           					<input type="submit" id="btn-newsletter-send-data" value="<?php echo __("Lưu cài đặt",THEMENAME);?>"> 
	           				</p>
	           			</div>
	           			<?php wp_nonce_field('act-newsletter-send-data','act_newsletter_send_data');?>
           			</form> 
           		</div> <!--  End newsletter l -->
           		           		
           		<!-- ++++++ -->
           		
           		<div class="newsletter-r">
           			<label><?php echo __("Xem trước nội dung email",THEMENAME);?></label>
           			<div class="newsletter-content">
           				<!-- ++++++++ -->
           					
           				
           				<!-- ++++++++ -->
           			</div>          			
           			
           		</div> <!--  End newsletter r -->
           	                        
           <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->	                    
	       </div>		             						             
  	</div>
<?php 	 	
}

function ws24_theme_func_subnewletter()
{
	$sourcePath = get_bloginfo('template_url').'/ws24options/';
	?>
		<link href="<?php echo $sourcePath;?>newsletter/newsletter.css" type="text/css" rel="stylesheet">	
		<script type="text/javascript" src="<?php echo $sourcePath;?>newsletter/newsletter.js"></script>	
		<div style="width: 98%;" id="my_theme_options_content">
	                
	         <div style="float: left; width: 100%;">
		         <h1 class="contactlist"><?php echo __("Đăng ký nhận tin qua email",THEMENAME);?></h1>
			  </div> 		       
	           <div class="box-tabs">        
	           <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
	           <?php   // Process form 
	            $newsletterdata = get_option("ws24-newsletter-data");	           
	           ?>
	           
	           <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
	           
	           		<div class="newsletter-l">
	           			<form action="" method="post">
		           			<div class="bl2">
		           				<p>
		           					<input checked="checked" type="radio" name="template-email" id="template-email1" value="default"> <?php echo __("Nội dung mặc định",WS24_THEMENAME);?>
		           					<input type="radio" name="template-email" id="template-email2" value="customer"> <?php echo __("Tạo mới nội dung",WS24_THEMENAME);?>
		           				</p>
		           				
		           				<p>
		           					<input type="text" name="subject" placeholder="<?php echo __('Subject',WS24_THEMENAME);?>" id="subject" value="<?php echo  ($newsletterdata['subject']);?>">
		           				</p>
		           				<!-- 
		           				<p>	
		           					<textarea rows="" cols="" name="content" id="content"><?php echo esc_attr(get_option("ws24-newsletter-data-content"));?></textarea>
		           				</p>
		           				-->
		           				<div style="float: left; width: 100%;">
		           				<?php 
		           				$content = $newsletterdata['content'];
		           				$editor_id = 'editpost';
		           				
		           				wp_editor( $content, $editor_id );
		           				?>	
		           				</div>
		           			</div>
		           			<div class="bl3">
		           				<p>
		           					<input type="submit" id="btn-newsletter-send-data" value="<?php echo __("Lưu cài đặt",THEMENAME);?>"> 
		           				</p>
		           			</div>
		           			<?php wp_nonce_field('act-newsletter-send-data','act_newsletter_send_data');?>
	           			</form> 
	           		</div> <!--  End newsletter l -->
	           		           		
	           		<!-- ++++++ -->
	           		<?php 
	           		$_newsletter = new ClNewsletter();
	           		$listnews = $_newsletter->get_all_newsletters();
	           		
	           		?>
	           		<div class="newsletter-r">
	           			<label class="tt"><?php echo __("Danh sách email đăng ký nhận tin",THEMENAME);?></label>
	           			<div class="newsletter-content">
	           				<ul id="list-newsletter1">
		           				<li class="newsletter-title">
		           					<label class="cols1">
		           						<input type="checkbox" name="" title="check all" value="" >
		           					</label>
		           					<label class="cols2">STT</label>
		           					<label class="cols3">Email</label>
		           				</li>
		           			</ul>	
	           				<ul id="list-newsletter">		           				
		           				<!-- ++++++++ -->
		           				<?php 
		           				if($listnews)
		           				{
		           					$tamp=1;
		           					foreach ($listnews as $value) 
									{
		           					?>
		           						<li>
		           							<label class="cols1">
		           								<input type="checkbox" name="" value="<?php $value->ID;?>">
		           							</label>
		           							<label class="cols2">
		           								<?php echo $tamp;?>
		           							</label>
		           							<label class="cols3">
		           								<?php echo $value->email;?>
		           							</label>
		           							
		           						</li>
		           					<?php 
		           						$tamp++;
		           					}
		           				}
		           				?>			
	           				</ul>
	           				<!-- ++++++++ -->
	           			</div>          			
	           			
	           		</div> <!--  End newsletter r -->
	           	                        
	           <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->	                    
		       </div>		             						             
	  	</div>
	<?php 
}
